//============================================================================
// Name        : MediaStorage.cpp
// Author      : chuanjiang.zh
// Version     :
// Copyright   : Copyright 2017 100wits.com
// Description : Hello World in C, Ansi-style
//============================================================================

#include <stdio.h>
#include <stdlib.h>
#include "MediaStorage.h"

#include "Ffmpeg.h"
#include "CMediaStorage.h"
#include "TSingleton.h"

#include "AppConst.h"
#include "AppConfig.h"
#include "StorageApplication.h"


namespace av
{

typedef comn::Singleton< CMediaStorage >	CMediaStorageSingleton;


void MediaStorage::startup()
{
	av_register_all();
	avformat_network_init();

	StorageApplication::instance().init();

}

void MediaStorage::cleanup()
{
    StorageApplication::instance().quit();

	avformat_network_deinit();
}

MediaStorage& MediaStorage::instance()
{
	return CMediaStorageSingleton::instance();
}


DLLEXPORT MediaStorage* createMediaStorage(const char* dbPath)
{
	CMediaStorage* storage = new CMediaStorage();

	storage->setDbPath(dbPath);

	return storage;
}

DLLEXPORT void destroyMediaStorage(MediaStorage* storage)
{
	MediaStorage& singleton = MediaStorage::instance();
	if (storage != &singleton)
	{
		storage->close();

		delete storage;
	}
}


}
